package com.bjqh.edu.UI.Fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bjqh.edu.R;
import com.bjqh.edu.adapter.Send3Adapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/9/6.
 */

public class OneOnOneFragment extends Fragment {
    public View mViewRoot;
    Unbinder unbinder;

    @BindView(R.id.tl_tab)
    TabLayout tlTab;
    @BindView(R.id.vp_content)
    ViewPager vpContent;
    private Send3Adapter adapter;

    private ArrayList<Fragment> datas;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //判断为空，为空就去加载布局，onCreateView在界面切换的时候会被多次调用,防止界面跳转回来的时候显示空白
        if (mViewRoot == null) {
            mViewRoot = inflater.inflate(R.layout.fragment_one_on_one, null);
            unbinder = ButterKnife.bind(this, mViewRoot);
        }

        unbinder = ButterKnife.bind(this, mViewRoot);
        datas = new ArrayList<>();
        datas.add(new PendingCoursesFragment());
        datas.add(new OKCoursesFragment());
        adapter = new Send3Adapter(getFragmentManager(), datas);//初始化fragment类型adapter,datas为adapter构造函数参数
        vpContent.setAdapter(adapter);
        //加入title选择和被选择的颜色,前面为未点击的颜色,后面为点击后的颜色
        tlTab.setTabTextColors(ContextCompat.getColor(getActivity(), R.color.white), ContextCompat.getColor(getActivity(), R.color.grean));
        tlTab.setSelectedTabIndicatorColor(ContextCompat.getColor(getActivity(), R.color.white));
        tlTab.setupWithViewPager(vpContent);//将tablayout与viewpager建立关系
        return mViewRoot;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        // liveRoom.quitRoom();

    }
}
